package com.travel.controller;

import com.travel.dto.CarOrderDto;
import com.travel.dto.LookForCarDto;
import com.travel.feign.CarOrderFeign;
import com.travel.feign.CarSearchFeign;
import com.travel.pojo.CarPackage;
import com.travel.pojo.CarRentalCompany;
import com.travel.service.CarPackageService;
import com.travel.vo.LookForCarVo;
import com.travel.vo.RentalDetailsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * (Order)表控制层
 *
 * @author makejava
 * @since 2023-05-10 14:54:29
 */
@RestController
@RequestMapping("carPackage")
@Api(tags = "汽车配套服务管理")
public class CarPackageController {
    /**
     * 服务对象
     */
    @Resource
    private CarPackageService carPackageService;

    @Resource
    private CarSearchFeign carSearchFeign;

//    @Resource
////    private CarOrderNumber carOrderNumber;

    @Resource
    private CarOrderFeign carOrderFeign;


    @GetMapping("/test")
    public void test() {
        String estest = carSearchFeign.estest();
        System.out.println(estest);
        System.out.println("===========");
        System.out.println("===========");
        System.out.println("===========");
    }


    /**
     * 查询所有的汽车套餐 以及图片
     */
    @ApiOperation(value = "查询套餐", notes = "查询汽车套餐notes")
    @GetMapping("/GetlistcarPackage")
    public List<LookForCarVo> GetlistcarPackage() {
        List<LookForCarVo> lookForCarVos = carPackageService.GetlistcarPackage();
        return lookForCarVos;
    }

    /**
     * es搜索汽车取车点
     *
     * @param
     * @return
     */
    @ApiOperation(value = "查询地点", notes = "查询地点notes")
    @GetMapping("/selectCarPackaage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键字", required = true, dataType = "String", paramType = "query")
    })
    public List<CarPackage> selectCarPackaage(String keyword) {
        List<CarPackage> packagePage = carSearchFeign.search(keyword, 0, 10);
        return packagePage;
    }

    /**
     * 点击搜索 将所选的取车城市的id传过来  然后将这个城市id的车辆查询出
     * （测试过）
     *
     * @return
     */
    @ApiOperation(value = "查询车辆所在地", notes = "查询车辆所在地notes")
    @GetMapping("/SearchVehicleLocation")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityid", value = "城市id", required = true, dataType = "String", paramType = "query")
    })
    public List<CarPackage> SearchVehicleLocation(@RequestParam Integer cityid) {
        List<CarPackage> packageList = carPackageService.SearchVehicleLocation(cityid);
        return packageList;
    }

    /**
     * 根据多个条件查询车辆
     *
     * @param lookForCarDto
     * @return
     */
    @ApiOperation(value = "查询车辆", notes = "查询车辆notes")
    @PostMapping("/MultiConditionScreening")
    public List<LookForCarVo> MultiConditionScreening(@RequestBody LookForCarDto lookForCarDto) {
        return carPackageService.MultiConditionScreening(lookForCarDto);
    }

    /**
     * 根据租车公司查询汽车
     */
    @ApiOperation(value = "租车公司", notes = "租车公司查询汽车notes")
    @GetMapping("/CarRentalCompany")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carCompanyId", value = "租车公司id", required = true, dataType = "String", paramType = "query")
    })
    public List<CarPackage> CarRentalCompany(@RequestParam("carCompanyId") Integer carCompanyId) {
        return carPackageService.CarRentalCompany(carCompanyId);
    }

    /**
     * 根据价格筛选车辆套餐
     *
     * @param
     * @return
     */
    @ApiOperation(value = "价格筛选", notes = "价格筛选查询汽车notes")
    @GetMapping("/PriceScreening")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "PriceState", value = "套餐价格", required = true, dataType = "String", paramType = "query")
    })
    public List<CarPackage> PriceScreening(@RequestParam("PriceState") Integer PriceState) {
        return carPackageService.PriceScreening(PriceState);
    }

    /**
     * 根据车辆id查询出有哪些公司有这个车
     *
     * @param carId
     * @return
     */
    @ApiOperation(value = "筛选公司", notes = "汽车id筛序公司notes")
    @GetMapping("/AToCarSearchCompany")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carId", value = "汽车id", required = true, dataType = "Integer", paramType = "query")
    })
    public List<CarRentalCompany> AToCarSearchCompany(@RequestParam("carId") Integer carId) {
        List<CarRentalCompany> carRentalCompanyList = carPackageService.AToCarSearchCompany(carId);
        return carRentalCompanyList;
    }


    /**
     * 根据公司id查询出有公司信息和这个车
     */
    @ApiOperation(value = "租车详情", notes = "租车详情页notes")
    @GetMapping("/RentalDetails")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carId", value = "汽车id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "carCompanyId", value = "租车公司id", required = true, dataType = "String", paramType = "query")
    })
    public RentalDetailsVo RentalDetails(Integer carId, Integer carCompanyId) {
        RentalDetailsVo rentalDetailsVo = carPackageService.RentalDetails(carId, carCompanyId);
        return rentalDetailsVo;
    }

    //todo  感觉还差一个总价从低到高的排序查询

    //todo  生成订单方法

    /**
     * 从前端传回来的数据  通过远程调用order服务 生成订单
     *
     * @return
     */
    @ApiOperation(value = "创建订单", notes = "根据dto创建Car order")
    @PostMapping("/AutomobileOrder")
    public HashMap<String, String> AutomobileOrder(@RequestBody CarOrderDto carOrderDto) {
        return carPackageService.AutomobileOrder(carOrderDto);
    }

    @ApiOperation(value = "生成订单号", notes = "生成订单号Car order")
    @GetMapping("/ObtainOrderNumber")
    public String ObtainOrderNumber(){
        //todo 调用服务
        String order =carOrderFeign.createOrder();
        System.out.println(order);
        return order;
    }

    //todo  调用支付

}

